package fr.afcepf.al22.qualite.data.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
import java.util.logging.Logger;

import javax.sql.DataSource;
/**
 * DataSource pour l'acces a la BDD 'al22'.
 * @author Stagiaire
 *
 */
public class Al22DataSource implements DataSource {
    /**
     * chaine de connexion a la bdd.
     */
    private static String url;
    /**
     * driver de connexion a la bdd.
     */
    private static String driver;
    /**
     * utilisateur de connexion a la bdd.
     */
    private static String login;
    /**
     * mot de passe de connexion a la bdd.
     */
    private static String pass;
    static {
        Properties props = new Properties();
        try {
            InputStream is =
                Thread.currentThread()
                .getContextClassLoader()
                .getResourceAsStream(
                "al22.properties");
            props.load(is);
            url = props.getProperty("url");
            login = props.getProperty("login");
            pass = props.getProperty("pass");
            driver = props.getProperty("driver");
            Class.forName(driver);
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    @Override
    public Connection getConnection() throws SQLException {
        Connection cnx = null;
        cnx = DriverManager.getConnection(url, login, pass);
        return cnx;
    }

    @Override
    public PrintWriter getLogWriter() throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void setLogWriter(PrintWriter paramOut) throws SQLException {
        // TODO Auto-generated method stub

    }

    @Override
    public void setLoginTimeout(int paramSeconds) throws SQLException {
        // TODO Auto-generated method stub

    }

    @Override
    public int getLoginTimeout() throws SQLException {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <T> T unwrap(Class<T> paramIface) throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public boolean isWrapperFor(Class<?> paramIface) throws SQLException {
        // TODO Auto-generated method stub
        return false;
    }


    @Override
    public Connection getConnection(String paramUsername, String paramPassword)
            throws SQLException {
        // TODO Auto-generated method stub
        return null;
    }

}
